<template>
	<view class="page-total">
		<view class="tab-list">
			<view class="list" v-for="(item,index) in TabBarList" @click="onTabBar(item,index)" :key="index" v-if="item.show">
				<image :src="item.acImg" mode="widthFix" v-show="tabBarShow === index"></image>
				<image :src="item.img" mode="widthFix" v-show="tabBarShow != index"></image>
				<text :class="{'action':tabBarShow===item.index}">{{item.name}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				TabBarList:[
					
				],
				codeheight: 0,
				isOverall: 0,
				phoneModel: '',
				seitch:''
			};
		},
		props:{
			tabBarShow: {
				type: Number,
				default: 0,
			}
		},
		mounted() {
			try {
			    const res = uni.getSystemInfoSync();
					let that = this;
			    // 获取系统信息
			    uni.getSystemInfo({
			    	success(res) {
			    		
						that.codeheight = Math.round(res.screenHeight);
						that.phoneModel =res.model
						if(res.model.search('iPhone')){
							that.isOverall = 0;
						}else if(Math.round(res.screenHeight)>740){
						 that.isOverall = 1;
						}
			    	}
			    });
			} catch (e) {
			    // error
			}
		},
		created() {
			console.log(1212)
			this.getSwith()
		},
		methods:{
			/**
			 * @param {Object} item
			 * @param {Number} index
			 */
			onTabBar(item,index){
				// this.tabBarShow = index;
				switch (item.index){
					case 0:
						wx.switchTab({
							url:'/pages/index/index'
						})
						break;
					case 1:
						wx.switchTab({
							url:'/pages/yingyang/yingyang'
						})
						break;
					case 2:
						wx.switchTab({
							url:'/pages/cart/cart'
						})
						break;
					case 3:
						wx.switchTab({
							url:'/pages/user/user'
						})
						break;
				}
			},
			getSwith(){
				let that = this
				that.tui.request("api.data/newSwitch", "POST", {}, false, false, true).then((res) => {
					console.log(res)
					if(res.code==1){
						that.seitch = res.data.switch
						if(res.data.switch==2){
							that.TabBarList=[
								{
									index: 0,
									name: '首页',
									img: '/static/tabbar/index.png',
									acImg: '/static/tabbar/index.png',
									show:true
								},
								{
									index: 2,
									name: '购物车',
									img: '/static/tabbar/cart.png',
									acImg: '/static/tabbar/cart.png',
									show:true
								},
								{
									index: 3,
									name: '我的',
									img: '/static/tabbar/user.png',
									acImg: '/static/tabbar/user.png',
									show:true
								},
							]
						}else{
							that.TabBarList=[
								{
									index: 0,
									name: '首页',
									img: '/static/tabbar/index.png',
									acImg: '/static/tabbar/index.png',
									show:true
								},
								{
									index: 1,
									name: '健康知识',
									img: '/static/tabbar/yingyang.png',
									acImg: '/static/tabbar/yingyang.png',
									show:true
								},
								{
									index: 2,
									name: '购物车',
									img: '/static/tabbar/cart.png',
									acImg: '/static/tabbar/cart.png',
									show:true
								},
								{
									index: 3,
									name: '我的',
									img: '/static/tabbar/user.png',
									acImg: '/static/tabbar/user.png',
									show:true
								},
							]
						}
					}
				}).catch((res) => {
					that.is_btn = false
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	@import 'TabBar.scss';
</style>
